import request from "@/utils/request";
import { useUserStore } from "@/stores/modules/user";

import type { AxiosPromise } from "axios";
import type { ChangeApi, PhoneEmailReq, WechatBindReq } from "./types";
import { vueMetaEnv } from "@/settings";

class ChangeApiImpl implements ChangeApi {
  // 更换手机号邮箱
  phoneEmail(data: PhoneEmailReq): AxiosPromise<boolean> {
    data.tenant = useUserStore().user.tenant;
    return request({
      url: "/v1/rbac/change/phone_email",
      method: "post",
      data: data,
    });
  }

  // 更换微信用户绑定
  /**
   * 绑定微信账号
   * @param {WechatBindReq} data - 微信绑定请求参数
   * @returns {AxiosPromise<boolean>} 返回绑定操作的结果Promise，成功时为true
   */
  wechatBind(data: WechatBindReq): AxiosPromise<boolean> {
    data.tenant = useUserStore().user.tenant;
    data.authorizerAppid = vueMetaEnv.APP_WECHAT_APPID;
    return request({
      url: "/v1/rbac/change/wechat_bind",
      method: "post",
      data: data,
    });
  }
}

export const changeApi = new ChangeApiImpl();
